package org.jboss.errai.ioc.client.api;

import com.me.client.local.App;
import com.me.client.shared.HelloMessage;
import com.me.client.shared.Response;
import java.lang.annotation.Annotation;
import java.util.Set;
import javax.enterprise.event.Event;
import org.jboss.errai.bus.client.api.Message;
import org.jboss.errai.enterprise.client.cdi.AbstractCDIEventCallback;
import org.jboss.errai.enterprise.client.cdi.CDIProtocol;
import org.jboss.errai.enterprise.client.cdi.EventProvider;
import org.jboss.errai.ioc.client.ContextualProviderContext;
import org.jboss.errai.ioc.client.InterfaceInjectionContext;
import org.jboss.errai.ioc.client.api.builtin.MessageBusProvider;
import org.jboss.errai.ioc.client.api.builtin.RequestDispatcherProvider;
import org.jboss.errai.ioc.client.api.builtin.RootPanelProvider;

public class BootstrapperImpl implements Bootstrapper {
  private native static void org_jboss_errai_enterprise_client_cdi_EventProvider_context(EventProvider instance, ContextualProviderContext value) /*-{
    instance.@org.jboss.errai.enterprise.client.cdi.EventProvider::context = value;
  }-*/;

  private native static ContextualProviderContext org_jboss_errai_enterprise_client_cdi_EventProvider_context(EventProvider instance) /*-{
    return instance.@org.jboss.errai.enterprise.client.cdi.EventProvider::context;
  }-*/;

  private native static void com_me_client_local_App_messageEvent(App instance, Event<HelloMessage> value) /*-{
    instance.@com.me.client.local.App::messageEvent = value;
  }-*/;

  private native static Event<HelloMessage> com_me_client_local_App_messageEvent(App instance) /*-{
    return instance.@com.me.client.local.App::messageEvent;
  }-*/;

  public InterfaceInjectionContext bootstrapContainer() {
    InterfaceInjectionContext ctx = new InterfaceInjectionContext();
    final RootPanelProvider inj1257 = new RootPanelProvider();
    final MessageBusProvider inj1262 = new MessageBusProvider();
    final RequestDispatcherProvider inj1250 = new RequestDispatcherProvider();
    final App inj1271 = new App();
    final EventProvider inj1245 = new EventProvider();
    org_jboss_errai_enterprise_client_cdi_EventProvider_context(inj1245, new ContextualProviderContext() {
      public Annotation[] getQualifiers() {
        return new Annotation[0];
      }

      public Class[] getTypeArguments() {
        return new Class[] { HelloMessage.class };
      }


    });
    com_me_client_local_App_messageEvent(inj1271, inj1245.get());
    final MessageBusProvider inj1266 = new MessageBusProvider();
    inj1266.get().subscribe("cdi.event:com.me.client.shared.Response", new AbstractCDIEventCallback() {
      public void callback(Message message) {
        Set<String> msgQualifiers = message.get(Set.class, CDIProtocol.Qualifiers);
        if (qualifiers.equals(msgQualifiers) || ((msgQualifiers == null) && qualifiers.isEmpty())) {
          inj1271.response(message.get(Response.class, CDIProtocol.BeanReference));
        }
      }


    });
    inj1271.buildUI();
    return ctx;
  }
}